

/**
 * 格式化样式格式
 * @param cssName 
 * @returns 
 */
let namespace_n = ''
const  HandlefilterName = (cssName)=>{
  let res_n = ''
  let o_n = cssName; 
 
           if(/#.*/g.test(o_n)){
              //  idNames 
           
              let id = o_n.replace(/#/g,'');
              res_n = `[id${namespace_n}="${id}"]`;  
           }else{
              // classNames
              res_n = `[class${namespace_n}="${o_n.replace(/^\./g,'')}"]`;  
           } 
           return res_n
 }
const variables = {} 
export default function({namespace}){
  namespace_n = namespace ?? 'name';
     return {
        postcssPlugin:'postcss-xxx',
         Declaration (node) { 
            let cache = node.parent.selector; 
            let selectName = '';
            // 判断入口文件
            // 由于访问者模式是会多次循环访问的
            if(!(/(classNames|idNames)="[^"]*[^"]*"/g.test(cache))){ 
              selectName = `[classNames="${cache}"]`;
          
              // 过滤携带注释的名称
              if((/\r\n.*/g.test(cache))){
                let filterName = cache.replace(/\r\n/g,'&').split('&')[1]; 
                  selectName = HandlefilterName(filterName); 
              }else{ 
                if(!/^\/\//.test(cache)){
               
                  selectName = HandlefilterName(cache); 
            
                } 
              }  
              node.parent.selector = selectName 
            } 
          
         },
         OnceExit(css){
               return css;  
         }
     }
}


